from django.db import models

from project.models import Project

# Create your models here.
class Endpoint(models.Model):
    """接口"""
    objects = models.QuerySet  # 将来会有用

    name = models.CharField("接口名称", max_length=32)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    method = models.CharField("方法",max_length=8)
    url = models.CharField("地址",max_length=255)

    # 参数
    params = models.JSONField("查询字符串",max_length=10240,blank=True, null=True)
    data = models.JSONField("表单参数",max_length=10240,blank=True, null=True)
    json = models.JSONField("json参数",max_length=10240,blank=True, null=True)
    headers = models.JSONField("请求头",max_length=10240,blank=True, null=True)


class Case(models.Model):
    """接口用例"""
    objects = models.QuerySet  # 将来会有用

    name = models.CharField("用例名称", max_length=32)
    project = models.ForeignKey(Project, on_delete=models.CASCADE)
    endpoint = models.ForeignKey(Endpoint, on_delete=models.CASCADE)

    allure = models.JSONField("allure标注",blank=True, null=True)
    # 用例步骤（实际传参）
    api_args = models.JSONField("接口用例参数",blank=True, null=True)
    # 数据提取
    extract = models.JSONField("数据提取",blank=True, null=True)
    # 断言
    validate = models.JSONField("断言")
    # todo 生成yaml文件
